package com.itheima.delaytask.service;

import com.itheima.delaytask.dto.Task;
import com.itheima.delaytask.exception.ScheduleSystemException;
import com.itheima.delaytask.exception.TaskNotExistException;

/**
 * Created by 传智播客*黑马程序员.
 */
public interface TaskService {
    
    /**
     * 添加任务
     *
     * @param task 任务对象
     * @return 任务id
     * @throws ScheduleSystemException
     */
    public long addTask(Task task) throws ScheduleSystemException;
    
    /**
     * 取消任务
     *
     * @param taskId 任务id
     * @return 取消结果
     * @throws TaskNotExistException
     */
    public boolean cancelTask(long taskId) throws TaskNotExistException, ScheduleSystemException;
    
    /**
     * 拉取消费任务，消费的是当前需要执行的任务
     *
     * @return
     * @throws TaskNotExistException
     */
    public Task poll() throws ScheduleSystemException;
    
    /**
     * 按照类型和优先级来拉取任务
     *
     * @param type
     * @param priority
     * @return
     * @throws ScheduleSystemException
     */
    public Task poll(int type, int priority) throws ScheduleSystemException;
    
    /**
     * 刷新
     */
    public void refresh();
}
